<template>
  <div class="user-page">
    <div class="user">
      <img :src="info.avatar" alt="" />
      <h3>{{info.username}}</h3>
    </div>

    <!-- 记录区域 -->
    <van-grid :column-num="3">
      <van-grid-item to="/article" icon="clock-o" text="历史记录" />
      <van-grid-item to="/collect" icon="bookmark-o" text="我的收藏" />
      <van-grid-item to="/like" icon="thumb-circle-o" text="我的点赞" />
    </van-grid>

    <!-- 功能区域 -->
    <van-cell-group  style="margin-top:20px">
    <van-cell title="推荐分享" is-link />
    <van-cell title="意见反馈" is-link  />
    <van-cell title="关于我们" is-link />
   <van-cell @click="logout" title="退出登录" is-link />
    </van-cell-group>
  </div>
</template>

<script>
import { removeToken } from '@/utils/storage'
import { userInfoAPI } from '@/api/user'
export default {
  name: 'user-page',
  data () {
    return {
      info: {}
    }
  },
  async created () {
    const res = await userInfoAPI()
    // console.log(res)
    this.info = res.data
  },
  methods: {
    logout () {
    //  弹出提示
      this.$toast.success('退出成功')
      // 删掉token
      removeToken()

      // 跳转登录页面
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less" scoped>
.user-page {
  padding: 0 10px;
  background: #f5f5f5;
  height: 100vh;
  .mt20 {
    margin-top: 20px;
  }
  .user {
    display: flex;
    padding: 20px 0;
    align-items: center;
    img {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      overflow: hidden;
    }
    h3 {
      margin: 0;
      padding-left: 20px;
      font-size: 18px;
    }
  }
}
</style>
